package com.yc.c118s3qnzf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.c118s3qnzf.entity.Users;
import com.yc.c118s3qnzf.mapper.UsersMapper;
import com.yc.c118s3qnzf.service.BizException;
import com.yc.c118s3qnzf.service.IUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-11-28
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Resource
    UsersMapper usersMapper;
    @Override
    public Users login(Users users) throws BizException {
       //条件构建器
        LambdaQueryWrapper<Users > lqw = new LambdaQueryWrapper<>();
        //username = ?
        lqw.eq(Users::getUsername, users.getUsername());
        //and password = ?
        lqw.eq(Users::getPassword, users.getPassword());
        Users dbusers = usersMapper.selectOne(lqw);
        if (dbusers == null){
            throw new BizException("用户名或密码错误");
        }
        return dbusers;

    }
}
